package o;

import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import o.aef.d;

final class aiy {
    private Format[] ʻ = new Format[this.ˎ];
    private int ʼ;
    private int ʽ;
    private int[] ˊ = new int[this.ˎ];
    private int ˊॱ;
    private int[] ˋ = new int[this.ˎ];
    private long ˋॱ = Long.MIN_VALUE;
    private int ˎ = 1000;
    private int[] ˏ = new int[this.ˎ];
    private int ˏॱ;
    private boolean ͺ;
    private long[] ॱ = new long[this.ˎ];
    private long ॱˊ = Long.MIN_VALUE;
    private boolean ॱˋ = true;
    private boolean ॱˎ = true;
    private d[] ॱॱ = new d[this.ˎ];
    private int ॱᐝ;
    private long[] ᐝ = new long[this.ˎ];
    private Format ᐝॱ;

    public static final class c {
        public d ˊ;
        public long ˋ;
        public int ॱ;
    }

    public void ˏ(boolean z) {
        this.ʽ = 0;
        this.ʼ = 0;
        this.ˏॱ = 0;
        this.ˊॱ = 0;
        this.ॱˎ = true;
        this.ॱˊ = Long.MIN_VALUE;
        this.ˋॱ = Long.MIN_VALUE;
        this.ͺ = false;
        if (z) {
            this.ᐝॱ = null;
            this.ॱˋ = true;
        }
    }

    public int ˋ() {
        return this.ʼ + this.ʽ;
    }

    public long ˏ(int i) {
        boolean z = true;
        int ˋ = ˋ() - i;
        boolean z2 = ˋ >= 0 && ˋ <= this.ʽ - this.ˊॱ;
        amm.ˊ(z2);
        this.ʽ -= ˋ;
        this.ˋॱ = Math.max(this.ॱˊ, ˋ(this.ʽ));
        if (!(ˋ == 0 && this.ͺ)) {
            z = false;
        }
        this.ͺ = z;
        if (this.ʽ == 0) {
            return 0;
        }
        int ˎ = ˎ(this.ʽ - 1);
        return ((long) this.ˊ[ˎ]) + this.ॱ[ˎ];
    }

    public int ˏ() {
        return this.ʼ + this.ˊॱ;
    }

    public synchronized boolean ॱ() {
        return this.ˊॱ != this.ʽ;
    }

    public synchronized Format ˎ() {
        return this.ॱˋ ? null : this.ᐝॱ;
    }

    public synchronized long ˊ() {
        return this.ˋॱ;
    }

    public synchronized boolean ᐝ() {
        return this.ͺ;
    }

    public synchronized void ʽ() {
        this.ˊॱ = 0;
    }

    public synchronized int ˊ(abk o_abk, DecoderInputBuffer decoderInputBuffer, boolean z, boolean z2, Format format, c cVar) {
        int i = -5;
        synchronized (this) {
            if (ॱ()) {
                int ˎ = ˎ(this.ˊॱ);
                if (z || this.ʻ[ˎ] != format) {
                    o_abk.ॱ = this.ʻ[ˎ];
                } else if (decoderInputBuffer.ʼ()) {
                    i = -3;
                } else {
                    decoderInputBuffer.ˏ = this.ᐝ[ˎ];
                    decoderInputBuffer.ˎ(this.ˏ[ˎ]);
                    cVar.ॱ = this.ˊ[ˎ];
                    cVar.ˋ = this.ॱ[ˎ];
                    cVar.ˊ = this.ॱॱ[ˎ];
                    this.ˊॱ++;
                    i = -4;
                }
            } else if (z2 || this.ͺ) {
                decoderInputBuffer.ˎ(4);
                i = -4;
            } else if (this.ᐝॱ == null || (!z && this.ᐝॱ == format)) {
                i = -3;
            } else {
                o_abk.ॱ = this.ᐝॱ;
            }
        }
        return i;
    }

    public synchronized int ॱ(long j, boolean z, boolean z2) {
        int i = -1;
        synchronized (this) {
            int ˎ = ˎ(this.ˊॱ);
            if (ॱ() && j >= this.ᐝ[ˎ] && (j <= this.ˋॱ || z2)) {
                int ॱ = ॱ(ˎ, this.ʽ - this.ˊॱ, j, z);
                if (ॱ != -1) {
                    this.ˊॱ += ॱ;
                    i = ॱ;
                }
            }
        }
        return i;
    }

    public synchronized int ॱॱ() {
        int i;
        i = this.ʽ - this.ˊॱ;
        this.ˊॱ = this.ʽ;
        return i;
    }

    public synchronized long ˋ(long j, boolean z, boolean z2) {
        long j2;
        if (this.ʽ == 0 || j < this.ᐝ[this.ˏॱ]) {
            j2 = -1;
        } else {
            int i;
            int ॱ;
            if (z2) {
                if (this.ˊॱ != this.ʽ) {
                    i = this.ˊॱ + 1;
                    ॱ = ॱ(this.ˏॱ, i, j, z);
                    if (ॱ != -1) {
                        j2 = -1;
                    } else {
                        j2 = ˊ(ॱ);
                    }
                }
            }
            i = this.ʽ;
            ॱ = ॱ(this.ˏॱ, i, j, z);
            if (ॱ != -1) {
                j2 = ˊ(ॱ);
            } else {
                j2 = -1;
            }
        }
        return j2;
    }

    public synchronized long ʼ() {
        long j;
        if (this.ʽ == 0) {
            j = -1;
        } else {
            j = ˊ(this.ʽ);
        }
        return j;
    }

    public synchronized boolean ˏ(Format format) {
        boolean z = false;
        synchronized (this) {
            if (format == null) {
                this.ॱˋ = true;
            } else {
                this.ॱˋ = false;
                if (!anr.ˎ((Object) format, this.ᐝॱ)) {
                    this.ᐝॱ = format;
                    z = true;
                }
            }
        }
        return z;
    }

    public synchronized void ˊ(long j, int i, long j2, int i2, d dVar) {
        if (this.ॱˎ) {
            if ((i & 1) != 0) {
                this.ॱˎ = false;
            }
        }
        amm.ˏ(!this.ॱˋ);
        this.ͺ = (536870912 & i) != 0;
        this.ˋॱ = Math.max(this.ˋॱ, j);
        int ˎ = ˎ(this.ʽ);
        this.ᐝ[ˎ] = j;
        this.ॱ[ˎ] = j2;
        this.ˊ[ˎ] = i2;
        this.ˏ[ˎ] = i;
        this.ॱॱ[ˎ] = dVar;
        this.ʻ[ˎ] = this.ᐝॱ;
        this.ˋ[ˎ] = this.ॱᐝ;
        this.ʽ++;
        if (this.ʽ == this.ˎ) {
            ˎ = this.ˎ + 1000;
            Object obj = new int[ˎ];
            Object obj2 = new long[ˎ];
            Object obj3 = new long[ˎ];
            Object obj4 = new int[ˎ];
            Object obj5 = new int[ˎ];
            Object obj6 = new d[ˎ];
            Object obj7 = new Format[ˎ];
            int i3 = this.ˎ - this.ˏॱ;
            System.arraycopy(this.ॱ, this.ˏॱ, obj2, 0, i3);
            System.arraycopy(this.ᐝ, this.ˏॱ, obj3, 0, i3);
            System.arraycopy(this.ˏ, this.ˏॱ, obj4, 0, i3);
            System.arraycopy(this.ˊ, this.ˏॱ, obj5, 0, i3);
            System.arraycopy(this.ॱॱ, this.ˏॱ, obj6, 0, i3);
            System.arraycopy(this.ʻ, this.ˏॱ, obj7, 0, i3);
            System.arraycopy(this.ˋ, this.ˏॱ, obj, 0, i3);
            int i4 = this.ˏॱ;
            System.arraycopy(this.ॱ, 0, obj2, i3, i4);
            System.arraycopy(this.ᐝ, 0, obj3, i3, i4);
            System.arraycopy(this.ˏ, 0, obj4, i3, i4);
            System.arraycopy(this.ˊ, 0, obj5, i3, i4);
            System.arraycopy(this.ॱॱ, 0, obj6, i3, i4);
            System.arraycopy(this.ʻ, 0, obj7, i3, i4);
            System.arraycopy(this.ˋ, 0, obj, i3, i4);
            this.ॱ = obj2;
            this.ᐝ = obj3;
            this.ˏ = obj4;
            this.ˊ = obj5;
            this.ॱॱ = obj6;
            this.ʻ = obj7;
            this.ˋ = obj;
            this.ˏॱ = 0;
            this.ʽ = this.ˎ;
            this.ˎ = ˎ;
        }
    }

    public synchronized boolean ˋ(long j) {
        boolean z = true;
        synchronized (this) {
            if (this.ʽ == 0) {
                if (j <= this.ॱˊ) {
                    z = false;
                }
            } else if (Math.max(this.ॱˊ, ˋ(this.ˊॱ)) >= j) {
                z = false;
            } else {
                int i = this.ʽ;
                int ˎ = ˎ(this.ʽ - 1);
                while (i > this.ˊॱ && this.ᐝ[ˎ] >= j) {
                    i--;
                    ˎ--;
                    if (ˎ == -1) {
                        ˎ = this.ˎ - 1;
                    }
                }
                ˏ(this.ʼ + i);
            }
        }
        return z;
    }

    private int ॱ(int i, int i2, long j, boolean z) {
        int i3 = -1;
        int i4 = 0;
        while (i4 < i2 && this.ᐝ[i] <= j) {
            if (!(z && (this.ˏ[i] & 1) == 0)) {
                i3 = i4;
            }
            int i5 = i + 1;
            if (i5 == this.ˎ) {
                i5 = 0;
            }
            i4++;
            i = i5;
        }
        return i3;
    }

    private long ˊ(int i) {
        this.ॱˊ = Math.max(this.ॱˊ, ˋ(i));
        this.ʽ -= i;
        this.ʼ += i;
        this.ˏॱ += i;
        if (this.ˏॱ >= this.ˎ) {
            this.ˏॱ -= this.ˎ;
        }
        this.ˊॱ -= i;
        if (this.ˊॱ < 0) {
            this.ˊॱ = 0;
        }
        if (this.ʽ != 0) {
            return this.ॱ[this.ˏॱ];
        }
        int i2 = (this.ˏॱ == 0 ? this.ˎ : this.ˏॱ) - 1;
        return ((long) this.ˊ[i2]) + this.ॱ[i2];
    }

    private long ˋ(int i) {
        long j = Long.MIN_VALUE;
        if (i == 0) {
            return Long.MIN_VALUE;
        }
        int i2 = 0;
        int ˎ = ˎ(i - 1);
        while (i2 < i) {
            long max = Math.max(j, this.ᐝ[ˎ]);
            if ((this.ˏ[ˎ] & 1) != 0) {
                return max;
            }
            int i3 = ˎ - 1;
            if (i3 == -1) {
                i3 = this.ˎ - 1;
            }
            i2++;
            ˎ = i3;
            j = max;
        }
        return j;
    }

    private int ˎ(int i) {
        int i2 = this.ˏॱ + i;
        return i2 < this.ˎ ? i2 : i2 - this.ˎ;
    }
}
